package cn.ym.org.controller;


import cn.ym.basic.utils.AjaxResult;
import cn.ym.basic.utils.PageList;
import cn.ym.org.domain.Employee;
import cn.ym.org.query.EmployeeQuery;
import cn.ym.org.service.EmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 接口类：员工
 */
@RestController
@RequestMapping("/employee")
@Api(value = "员工接口" ,description = "处理员工的所有请求")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
    /**
     * 接口：添加或修改员工信息
     */
    @ApiOperation(value = "添加或修改员工信息")
    @PutMapping
    public AjaxResult save(@RequestBody @Validated Employee employee){

            if(employee.getId()==null){
                employeeService.add(employee);
            }else {
                employeeService.update(employee);
            }
            return new AjaxResult();


    }

    /**
     *接口：删除单个员工信息
     */
    @ApiOperation(value = "删除单个员工信息")
    @DeleteMapping("/{id}")
    public AjaxResult del(@PathVariable("id") Long id){

            employeeService.delete(id);
            return new AjaxResult();

    }

    /**
     * 接口：查询所有员工信息
     */
    @ApiOperation(value = "查询所有员工信息")
    @GetMapping
    public List<Employee> findAll(){
        return employeeService.findAll();
    }

    /**
     * 接口：查询单个员工信息
     */
    @ApiOperation(value = "查询单个员工信息")
    @GetMapping("/{id}")
    public Employee findOne(@PathVariable("id") Long id){
        return employeeService.findOne(id);
    }


    /**
     * 接口：批量删除员工信息
     */
    @ApiOperation(value = "批量删除员工信息")
    @PatchMapping
    public AjaxResult patchDel(@RequestBody Long[]  ids){

            employeeService.patchDel(ids);
            return new AjaxResult();

    }

    /**
     * 接口：分页查询 + 高级查询
     */
    @ApiOperation(value = "分页查询或高级查询")
    @PostMapping
    public PageList<Employee> queryPage(@RequestBody EmployeeQuery employeeQuery){
        return employeeService.queryPage(employeeQuery);
   }


}
